namespace :db do
  desc "Empty the current database"
  task :purge => :environment do
    return if %w[production].include? RAILS_ENV
    config = ActiveRecord::Base.configurations[RAILS_ENV]
    ActiveRecord::Base.connection.recreate_database(config['database'])
    ActiveRecord::Base.establish_connection
  end

  desc "Migrate with catlike tread"
  task :migrate_quietly => :environment do
    ActiveRecord::Migration.verbose = false
    Rake::Task['db:migrate'].invoke
  end

  task :clear_load_paths do
    @old_load_paths = Dependencies.load_paths
    Dependencies.load_paths = []
  end

  task :migrate => :clear_load_paths do
    Dependencies.load_paths = @old_load_paths
  end

  desc "Empty and recreate the current database"
  task :remigrate => [:purge, :migrate_quietly]
end